package object.homework;

/**
 * matches()：匹配，使用给定的正则表达式验证当前字符串的格式是否符合要求，若符合则返回true，不符合则返回false
 */
public class MatchesDemo {
    public static void main(String[] args) {
        String email = "xiaopenyou@qq.com";
        String  regex = "[a-zA-Z0-9_]+@[a-zA-Z0-9]+(\\.[a-zA-Z]+)+";
        boolean match = email.matches(regex);
        if (match){
            System.out.println("正确");
        }else {
            System.out.println("错误");
        }
        /*
            邮箱正则表达式:
            [a-zA-Z0-9_]+@[a-zA-Z0-9]+(\.[a-zA-Z]+)+
        */
        /*
        String email = "wangkj@tedu.cn";
        String regex = "[a-zA-Z0-9_]+@[a-zA-Z0-9]+(\\.[a-zA-Z]+)+";
        boolean bool = email.matches(regex);
        if (bool){
            System.out.println("正确");
        }else {
            System.out.println("错误");
        }

         */

    }
}
